﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using LogicGates;
using MipsProject;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void AndDemo_Click(object sender, EventArgs e)
    {
        this.resetCheckBoxes();

        TextBox1.Text += String.Format("Demonstrating AND instruction:\n");
        int ALU_SIZE = 32;
        ALU alu = new ALU(ALU_SIZE);
        int input1 = 100, input2 = 32;
        int result;
        result = alu.Execute(OpCode.AND, input1, input2);
        TextBox1.Text += String.Format("  Result of {1} AND {2} = {0}\n\n", result, input1, input2);

        if (alu.ZeroFlag)
            ZeroCheckBox.Checked = true;

        if (alu.OverflowFlag)
            OverflowCheckBox.Checked = true;

        if (alu.CarryFlag)
            CarryCheckBox.Checked = true;
    }
    protected void OrDemo_Click(object sender, EventArgs e)
    {
        this.resetCheckBoxes();

        TextBox1.Text += String.Format("Demonstrating OR instruction:\n");
        int ALU_SIZE = 32;
        ALU alu = new ALU(ALU_SIZE);
        int input1 = 100, input2 = 32;
        int result;
        result = alu.Execute(OpCode.OR, input1, input2);
        TextBox1.Text += String.Format("  Result of {1} OR {2} = {0}\n\n", result, input1, input2);

        if (alu.ZeroFlag)
            ZeroCheckBox.Checked = true;

        if (alu.OverflowFlag)
            OverflowCheckBox.Checked = true;

        if (alu.CarryFlag)
            CarryCheckBox.Checked = true;
    }
    protected void AddDemo_Click(object sender, EventArgs e)
    {
        this.resetCheckBoxes();

        TextBox1.Text += String.Format("Demonstrating ADD instruction:\n");
        int ALU_SIZE = 32;
        ALU alu = new ALU(ALU_SIZE);
        int input1 = 100, input2 = 32;
        int result;
        result = alu.Execute(OpCode.ADD, input1, input2);
        TextBox1.Text += String.Format("  Result of {1} ADD {2} = {0}\n\n", result, input1, input2);

        if (alu.ZeroFlag)
            ZeroCheckBox.Checked = true;

        if (alu.OverflowFlag)
            OverflowCheckBox.Checked = true;

        if (alu.CarryFlag)
            CarryCheckBox.Checked = true;
    }
    protected void SubDemo_Click(object sender, EventArgs e)
    {
        this.resetCheckBoxes();

        TextBox1.Text += String.Format("Demonstrating SUB instruction:\n");
        int ALU_SIZE = 32;
        ALU alu = new ALU(ALU_SIZE);
        int input1 = 100, input2 = 32;
        int result;
        result = alu.Execute(OpCode.SUB, input1, input2);
        TextBox1.Text += String.Format("  Result of {1} SUB {2} = {0}\n\n", result, input1, input2);

        if (alu.ZeroFlag)
            ZeroCheckBox.Checked = true;

        if (alu.OverflowFlag)
            OverflowCheckBox.Checked = true;

        if (alu.CarryFlag)
            CarryCheckBox.Checked = true;
    }
    protected void SltDemo_Click(object sender, EventArgs e)
    {
        this.resetCheckBoxes();

        TextBox1.Text += String.Format("Demonstrating SLT instruction:\n");
        int ALU_SIZE = 32;
        ALU alu = new ALU(ALU_SIZE);
        int input1 = 100, input2 = 32;
        int result;
        result = alu.Execute(OpCode.SLT, input1, input2);
        TextBox1.Text += String.Format("  Result of {1} SLT {2} = {0}\n\n", result, input1, input2);

        if (alu.ZeroFlag)
            ZeroCheckBox.Checked = true;

        if (alu.OverflowFlag)
            OverflowCheckBox.Checked = true;

        if (alu.CarryFlag)
            CarryCheckBox.Checked = true;
    }
    protected void NorDemo_Click(object sender, EventArgs e)
    {
        this.resetCheckBoxes();

        TextBox1.Text += String.Format("Demonstrating NOR instruction:\n");
        int ALU_SIZE = 32;
        ALU alu = new ALU(ALU_SIZE);
        int input1 = 100, input2 = 32;
        int result;
        result = alu.Execute(OpCode.NOR, input1, input2);
        TextBox1.Text += String.Format("  Result of {1} NOR {2} = {0}\n\n", result, input1, input2);

        if (alu.ZeroFlag)
            ZeroCheckBox.Checked = true;

        if (alu.OverflowFlag)
            OverflowCheckBox.Checked = true;

        if (alu.CarryFlag)
            CarryCheckBox.Checked = true;
    }

    protected void resetCheckBoxes()
    {
        ZeroCheckBox.Checked = false;
        OverflowCheckBox.Checked = false;
        CarryCheckBox.Checked = false;
    }
}